import {NgModule} from '@angular/core';
import {Routes, RouterModule} from '@angular/router';

// Layouts
import {FullLayoutComponent} from './layouts/full-layout.component';
import {LoginComponent} from './pages/login/login.component';

// preloading
import {SelectivePreloadingStrategy} from './app.preloading-strategy';

const permissions: any = (localStorage.permissionList && JSON.parse(localStorage.permissionList).length !== 0) ? JSON.parse(localStorage.permissionList) : [{controller: ''}];
// const permissions: any = localStorage.permissions ? JSON.parse(localStorage.permissions) : [{controller: ''}];
const redirectUrl: any = permissions[0].controller ? permissions[0].controller + '/index' : 'login';
const route_login: any = {
    path: '',
    redirectTo: redirectUrl,
    pathMatch: 'full'
};
export const routes: Routes = [
    {
        path: 'login',
        component: LoginComponent,
    },
    route_login,
    {
        path: '',
        component: FullLayoutComponent,
        data: {
            title: '后台管理中心'
        }, children: [
        // 用户管理
        {
            path: 'users',
            loadChildren: './pages/user/user.module#UserModule',
            data: {
                preload: true
            }
        },
        // 活动管理
        {
            path: 'activity',
            loadChildren: './pages/activity/activity.module#ActivityModule',
            data: {
                preload: true
            }
        },
        // 充值管理
        {
            path: 'recharge-record',
            loadChildren: './pages/recharge-record/recharge-record.module#RechargeRecordModule',
            data: {
                preload: true
            }
        },
        {
            path: 'operate-user',
            loadChildren: './pages/operate-user/operate-user.module#OperateUserModule',
            data: {
                preload: true
            }
        },
        {
            path: 'message',
            loadChildren: './pages/message/message.module#MessageModule',
            data: {
                preload: true
            }
        },
        {
            path: 'role',
            loadChildren: './pages/role/role.module#RoleModule',
            data: {
                preload: true
            }
        },
        {
            path: 'withdrawals',
            loadChildren: './pages/withdrawals/withdrawals.module#WithdrawalsModule',
            data: {
                preload: true
            }
        },
        {
            path: 'passwordmodify',
            loadChildren: './pages/password-modify/password-modify.module#PasswordModifyModule',
            data: {
                preload: true
            }
        },
    ]
    }
];

@NgModule({
    imports: [RouterModule.forRoot(routes, {preloadingStrategy: SelectivePreloadingStrategy})],
    exports: [RouterModule],
    providers: [SelectivePreloadingStrategy]
})
export class AppRoutingModule {
}
